package com.itheima.demo01;

import java.io.IOException;
import java.util.concurrent.Callable;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/11 19:21
 */
public class Ticket implements Callable<String> {
    private int ticket = 100;

    @Override
    public String call() {
        while (true) {
            synchronized ("this") {
                if (ticket <= 0) {
                    break;
                } else {
                    try {
                        Thread.sleep(1);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    ticket--;
                    System.out.println(Thread.currentThread().getName() + "窗口正在售票,还剩下" + ticket + "张票!");
                }
            }
        }
        return "票卖完了";
    }
}

